//
//  Medium_MusicCD04_01.swift
//  TimMusic
//
//  Created by nkl on 2024/10/29.
//

import Foundation
import SwiftUI

struct Medium_MusicCD04_01: View {
    var model: ControlMusicModel
    var body: some View {
        ZStack {
            GeometryReader { geometry in
                VStack(spacing: 0) {
                    Color(hex: "#111111")
                        .frame(height: geometry.size.height * 2 / 3) // 2:1 的比例
                    ZStack {
                        Color(hex: "#2f1b16")

                        HStack {
                            Spacer()
                            Image("ic_widget_last").resizable().frame(width: 40, height: 40)
                                .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.playlast.rawValue)", isStatic: model.isStatic))
                            if model.isPlay {
                                Image("ic_widget_pause").resizable().frame(width: 40, height: 40)
                                    .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.pause.rawValue)", isStatic: model.isStatic))
                            } else {
                                Image("ic_widget_play").resizable().frame(width: 40, height: 40)
                                    .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.play.rawValue)", isStatic: model.isStatic))
                            }
                            Image("ic_widget_next").resizable().frame(width: 40, height: 40)
                                .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.playnext.rawValue)", isStatic: model.isStatic))
                        }.padding(.trailing, 40)

                    }.frame(height: geometry.size.height / 3)
                }
            }

            HStack {
                ZStack {
                    Image("ic_medium_cd_bg").resizable().frame(width: 140, height: 140)
                    if let data = model.imageData, let uiImage = UIImage(data: data) {
                        Image(uiImage: uiImage).resizable().frame(width: 107, height: 107).offset(x: -15.0)

                    } else {
                        Image("ic_small_placeholder").resizable().frame(width: 107, height: 107).offset(x: -15.0)
                    }
                }

                VStack(alignment: .leading) {
                    TMText(title: model.title, font: 18, color: .white, align: .leading, numberOflines: 1)
                    Spacer().frame(height: 8)
                    TMText(title: model.auth, font: 12, color: .white, align: .leading, numberOflines: 1)
                }.padding(.bottom, 20)

            }.padding(.horizontal)
        }
    }
}

#Preview {
    Medium_MusicCD04_01(model: .init(title: "", auth: "", imageData: nil, isPlay: false, isStatic: true))
}
